package com.jd.learn.controller;

import com.jd.learn.mapper.UserInfoMapper;
import com.jd.learn.mapper.UserMapper;
import com.jd.learn.entity.SysUser;
import com.jd.learn.entity.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserController {

    @Resource
    private UserMapper userMapper;

    @Resource
    private UserInfoMapper userInfoMapper;

    /**
     * https://gitee.com/ityouknow/spring-boot-examples.git
     * 获取用户列表
     * @return   List
     */
    @RequestMapping("/users")
    public List<User> getUsers() {
        List<User> users = userMapper.getAll();
        return users;
    }

    @RequestMapping("/list")
    public List<SysUser> getAll() {
        List<SysUser> users = userInfoMapper.queryUsers();
        return users;
    }

    @RequestMapping("/insert")
    public User insertUsers() {
        User user = new User();
        int max = 1000;
        int min = 1;
        int randomWithMathRandom = (int) ((Math.random() * (max - min)) + min);

        user.setEmail("zhangxiaolong@jd.com");
        user.setMobile("15010141646");
        user.setUsername("zhangxiaolong");

        userMapper.insert(user);
        return user;
    }


}
